import requests,unittest

class A3mall(unittest.TestCase):
    token=None
    #login 登录
    def test_A3mall_01_login(self):
        url = 'http://10.59.9.14:7003/api/public/login'
        josn = {"username": "17733058407", "password": "li123456"}

        login=requests.post(url=url,json=josn)
        print(login.json())
        A3mall.token=login.json()['data']['token']
        print(A3mall.token)

    #info 我的
    def test_A3mall_02_info(self):
        url='http://10.59.9.14:7003/api/ucenter/info'
        headers={'Auth-Token':'Bearer '+A3mall.token}
        info=requests.get(url=url,headers=headers)
        print(info.json())

    #regiment 团购列表
    def test_A3mall_03_regiment(self):
        url='http://10.59.9.14:7003/api/regiment?page=1&type=0&sort=1'
        regiment=requests.get(url=url)
        print(regiment.json())

    #view 团购商品详情
    def test_A3mall_04_view(self):
        url = 'http://10.59.9.14:7003/api/regiment/view?id=7'
        view = requests.get(url=url)
        print(view.json())

    #index 支付方式
    def test_A3mall_05_index(self):
        url = 'http://10.59.9.14:7003/api/payment/index'
        josn = {"type":"h5","pay_type":"order"}
        index = requests.post(url=url, json=josn)
        print(index.json())

    # confirm 创建订单
    def test_A3mall_06_confrim(self):
        url = 'http://10.59.9.14:7003/api/order/confirm?id=7&type=regiment&sku_id=&num=1&shipping_type=1'
        headers = {'Auth-Token':'Bearer ' + A3mall.token}
        confirm = requests.get(url=url,headers=headers)
        print(confirm.json())

    # create 支付成功
    def test_A3mall_07_create(self):
        url = 'http://10.59.9.14:7003/api/order/create'
        josn = {"id": "17", "type": "second", "address_id": 179, "store_id": "0", "shipping_type": 1,
                "bonus_id": "0", "payment": "balance", "remarks": "", "source": 1,
                "url": "http://10.59.9.14:7003/wap/pages/cart/confirm?id=17&sku_id=&num=1&type=second",
                "sku_id": "", "num": "1"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        create = requests.post(url=url, json=josn, headers=headers)
        print(create.json())

    # detail 查看订单
    def test_A3mall_08_detail(self):
        url = 'http://10.59.9.14:7003/api/order/detail'
        josn = {"id":"154343"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        detail = requests.post(url=url, json=josn, headers=headers)
        print(detail.json())

    # delivery 确认订单
    def test_A3mall_09_delivery(self):
        url = 'http://10.59.9.14:7003/api/order/delivery'
        josn = {"id":"154343"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        delivery = requests.post(url=url, json=josn, headers=headers)
        print(delivery.json())

    # confirm_delivery 确认收货
    def test_A3mall_10_confirm_delivery(self):
        url = 'http://10.59.9.14:7003/api/order/confirm_delivery'
        josn = {"id":"154343"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        delivery = requests.post(url=url, json=josn, headers=headers)
        print(delivery.json())


if __name__ == '__main__':
    unittest.main()